/**
 * @Time    : 2021/5/31 18:04
 * @Author  : WanRongJia
 * @License : Software business license
 * @Site    : www.rich-f.com
 * @File    : handleError.js
 * @Software: Rich Web Platform
 * @Function: 错误处理
 * @Version : 1.0
 **/

let logger = require('log4js').getLogger("default");

const handleError = (res = {}, err = {}) => {
    const errorMessage = { // 统一错误码返回信息
        500: '服务器内部错误',
        503: '服务不可用',
    }

    logger.error(err.message);
    // Sends error to user
    res.status(200).json({
        code: err.code,
        message: err.message || errorMessage[err.code],
        status: false
    })
};

module.exports = { handleError }